'use strict';

stareal
    .controller("RaidersController", function ($scope, $stateParams, $api, $sce, base64, $state, $alert,localStorageService,$timeout) {
        $scope.mypage = 2;
        // var  Myswiper = new Swiper('.Repertoire_container', {
        //     freeMode: true,
        //     slidesPerView: '2',
        //     freeModeSticky: true,
        //     observer:true,//修改swiper自己或子元素时，自动初始化swiper
        // })

        var h=$(window).height()-3.0*parseFloat(document.documentElement.style.fontSize)+"px";
        $("#wrapper_container").height(h);
        //埋点
        $scope.maiDian=function(type,action,label,id){
            if(_czc!=undefined&&_czc!=null&&_czc!='') {
                _czc.push(["_trackEvent", type, action, label, '', id]);
            }
        }
        //列表 热门
        // $api.get("app/good/classifyid",{kindid:"",name:"",cityid:'',hot:'',score:'',pageNum:1,pageSize:15},true)
        //     .then(function (ret) {
        //         $scope.latest = ret.data  //列表
        //     })
        $scope.localeCityId=localStorageService.get('cityid');
        //获取城市
        $scope.localeCityId=localStorageService.get('cityid');
        if( $scope.localeCityId==null||$scope.localeCityId==undefined){
            $api.get("app/city/list")
                .then(function (ret){
                    $scope.cities=ret.data;
                    var  map= new AMap.Map('position_center');
                    //实例化城市
                    var geolocation = null;
                    map.plugin('AMap.Geolocation', function () {
                        geolocation = new AMap.Geolocation({
                            enableHighAccuracy: true,//是否使用高精度定位，默认:true
                            timeout: 10000,          //超过10秒后停止定位，默认：无穷大
                            maximumAge: 0,           //定位结果缓存0毫秒，默认：0
                            convert: true,           //自动偏移坐标，偏移后的坐标为高德坐标，默认：true
                            showButton: true,        //显示定位按钮，默认：true
                            buttonPosition: 'LB',    //定位按钮停靠位置，默认：'LB'，左下角
                            buttonOffset: new AMap.Pixel(10, 20),//定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)
                            showMarker: true,        //定位成功后在定位到的位置显示点标记，默认：true
                            showCircle: true,        //定位成功后用圆圈表示定位精度范围，默认：true
                            panToLocation: true,     //定位成功后将定位到的位置作为地图中心点，默认：true
                            zoomToAccuracy:true      //定位成功后调整地图视野范围使定位位置及精度范围视野内可见，默认：false
                        });
                        map.addControl(geolocation);
                        geolocation.getCurrentPosition(function(status,result){
                            if(status=='complete'){
                                if(result.addressComponent.city!=''&&result.addressComponent.city!=null&&result.addressComponent.city!=undefined){
                                    var arr=result.addressComponent.city.split('市');
                                }else{
                                    var arr=result.addressComponent.province.split('市');
                                }
                                localStorageService.set('longitude',result.position.lng);
                                localStorageService.set('latitude',result.position.lat);
                                localStorageService.set('currentPOSITIONID',arr[0]);
                                for(var i=0;i< $scope.cities.length;i++) {
                                    if ($scope.cities[i].name == arr[0]) {
                                        $("#current_city").html($scope.cities[i].name);
                                        $scope.currentPOSITIONID=$scope.cities[i].name
                                        localStorageService.set('cityid', $scope.cities[i].id);
                                        localStorageService.set('cityname', $scope.cities[i].name);
                                    }
                                }
                                $("#current_ationSHOW").show();
                            }else{
                                $alert.show('定位失败！');
                                $("#current_city").html("全国");
                                localStorageService.set('cityname', "全国");
                                localStorageService.set('cityid','-1');//全国默认
                            }

                        });
                    });
                });
        }else{
            $("#current_city").html(localStorageService.get('cityname'));
        }
        $scope.hotsFUN=function(){
            $api.get("app/good/hot",{pageNum:1,pageSize:15,cityid:$scope.localeCityId},true)
                .then(function (ret) {
                    $scope.goodshot = ret.data  //列表
                    $scope.ranksgood();
                })
        }


        $scope.hotsFUN();

        // $scope.alertShow=function(){
        //     $alert.show("敬请期待！");
        // }
        //列表  热门演出
        $scope.completeHotRepertoireRepeat=function(){
            var swiper = new Swiper('#hot_Repertoire_container', {
                slidesPerView: 'auto',
                spaceBetween:0,
                pagination: '.hot_Repertoire-pagination',//分页容器
                // prevButton:'.swiper-button-prev',
                // nextButton:'.swiper-button-next',
                observer:true,//修改swiper自己或子元素时，自动初始化swiper

            })
            $timeout(function () {
                swiper.setWrapperTransition(0);
                /**设置位移0 显示第一页 */
                swiper.setWrapperTranslate(0);
            },500)
        }





        //  热门观演记
        $scope.ranksgood=function(){
            $api.get("app/view/hot",{ page_num: 1,page_size: 10,flag:1},true)
                .then(function (ret) {
                    var data=ret.data;
                  $scope.hotsViews=data;
                    $scope.hotMydeersView();
                })
        }
        //独家攻略  app/celebritys/list
        $scope.hotMydeersView=function(){
            $api.get("app/celebritys/list",{ page_num: 1,page_size: 10},true)
                .then(function (ret) {
                    var data=ret.data;
                    $scope.hotsMydeersViews=data;
                })
        }

    });